<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>干扰告警参数管理</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">

	getData();	
	function getData(){
		var url = "${pageContext.request.contextPath}/interferencequery/interferenceconfig.do";  
		var data = {type:1};
		$.ajax({   type : "get",   async : true, //同步请求   
			url : url,   
			data : data,      
			dataType:"json",
			success:function(dates){
				//转为JSON对象
			var dataObj=JSON.stringify(dates); 
			var val = JSON.parse(dataObj);
			var dataObj1=JSON.stringify(val.alarmConfig);  
			var val1 = JSON.parse(dataObj1);
			var value1=val1[1];
			var len1=value1.length-1;
			$('#haveFSinf1').combobox('setValue', value1[0]);
			$('#left1').combobox('setValue', value1[1]-1);
			$('#right1').combobox('setValue', value1[len1]-1);
			var value2=val1[2];
			var len2=value2.length-1;
			$('#haveFSinf2').combobox('setValue', value2[0]);
			$('#left2').combobox('setValue', value2[1]-1);
			$('#right2').combobox('setValue', value2[len2]-1);
			var value3=val1[3];
			var len3=value3.length-1;
			$('#haveFSinf3').combobox('setValue', value3[0]);
			$('#left3').combobox('setValue', value3[1]-1);
			$('#right3').combobox('setValue', value3[len3]-1);
			var value4=val1[4];
			var len4=value4.length-1;
			$('#haveFSinf4').combobox('setValue', value4[0]);
			$('#left4').combobox('setValue', value4[1]-1);
			$('#right4').combobox('setValue', value4[len4]-1);
			var value5=val1[5];
			var len5=value5.length-1;
			$('#haveFSinf5').combobox('setValue', value5[0]);
			$('#left5').combobox('setValue', value5[1]-1);
			$('#right5').combobox('setValue', value5[len5]-1);
			},   
			error: function() {
				alert("获取数据失败，请稍后再试！");
			}  
			});   
	}
	function refresh(){
		getData();
	}
	
    //验证输入是否符合要求的连续，并修改
	function submitData(){
		var submit="{\"1\":";
		var haveFs = 8;
		var withoutFs = 8;
		var val1=$('#haveFSinf1').combobox('getValue');
		var lef1=$('#left1').combobox('getText');
		var rig1=$('#right1').combobox('getText');
		if(val1>0){
			if(haveFs-rig1>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			submit=submit+"[1,";
			haveFs=lef1;
			for(var i=lef1;i<=rig1;i++){
			    submit=submit+i+"";
			    if(i<rig1){
			    	submit=submit+",";
			    }
			}
			submit=submit+"],"
		}
		else{
			submit=submit+"[0,";
			if(withoutFs-rig1>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			withoutFs=lef1;
			for(var i=lef1;i<=rig1;i++){
			    submit=submit+i+"";
			    if(i<rig1){
			    	submit=submit+",";
			    }
			}
			submit=submit+"],"
		}
		var val2=$('#haveFSinf2').combobox('getValue');
		var lef2=$('#left2').combobox('getText');
		var rig2=$('#right2').combobox('getText');
		if(val2>0){
			if(haveFs-rig2>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			submit=submit+"\"2\":[1,";
			haveFs=lef2;
			for(var i=lef2;i<=rig2;i++){
			    submit=submit+i+"";
			    if(i<rig2){
			    	submit=submit+",";
			    }
			}
			submit=submit+"],"
		}
		else{
			submit=submit+"\"2\":[0,";
			if(withoutFs-rig2>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			withoutFs=lef2;
			for(var i=lef2;i<=rig2;i++){
			    submit=submit+i+"";
			    if(i<rig2){
			    	submit=submit+",";
			    }
			}
			submit=submit+"],"
		}
		var val3=$('#haveFSinf3').combobox('getValue');
		var lef3=$('#left3').combobox('getText');
		var rig3=$('#right3').combobox('getText');
		if(val3>0){
			if(haveFs-rig3>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			submit=submit+"\"3\":[1,";
			haveFs=lef3;
			for(var i=lef3;i<=rig3;i++){
			    submit=submit+i+"";
			    if(i<rig3){
			    	submit=submit+",";
			    }
			}
			submit=submit+"],"
		}
		else{
			submit=submit+"\"3\":[0,";
			if(withoutFs-rig3>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			withoutFs=lef3;
			for(var i=lef3;i<=rig3;i++){
			    submit=submit+i+"";
			    if(i<rig3){
			    	submit=submit+",";
			    }
			}
			submit=submit+"],"
		}
		var val4=$('#haveFSinf4').combobox('getValue');
		var lef4=$('#left4').combobox('getText');
		var rig4=$('#right4').combobox('getText');
		if(val4>0){
			if(haveFs-rig4>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			submit=submit+"\"4\":[1,";
			haveFs=lef4;
			for(var i=lef4;i<=rig4;i++){
			    submit=submit+i+"";
			    if(i<rig4){
			    	submit=submit+",";
			    }
			}
			submit=submit+"],"
		}
		else{
			submit=submit+"\"4\":[0,";
			if(withoutFs-rig4>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			withoutFs=lef4;
			for(var i=lef4;i<=rig4;i++){
			    submit=submit+i+"";
			    if(i<rig4){
			    	submit=submit+",";
			    }
			}
			submit=submit+"],"
		}
		var val5=$('#haveFSinf5').combobox('getValue');
		var lef5=$('#left5').combobox('getText');
		var rig5=$('#right5').combobox('getText');
		if(val5>0){
			if(haveFs-rig5>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			submit=submit+"\"5\":[1,";
			haveFs=lef5;
			for(var i=lef5;i<=rig5;i++){
			    submit=submit+i+"";
			    if(i<rig5){
			    	submit=submit+",";
			    }
			}
			submit=submit+"]}"
		}
		else{
			submit=submit+"\"5\":[0,";
			if(withoutFs-rig5>1){
				$.messager.alert("系统提示","请输入连续的RxQual");
				return;
			}
			withoutFs=lef5;
			for(var i=lef5;i<=rig5;i++){
			    submit=submit+i+"";
			    if(i<rig5){
			    	submit=submit+",";
			    }
			}
			submit=submit+"]}"
		}	
		$.post("${pageContext.request.contextPath}/interferencequery/insertalarmconfig.do",{AlarmConfig:submit},function(result){
				if(result.success){
					 $.messager.alert("系统提示","参数应用成功！");
				}else{
					$.messager.alert("系统提示","参数应用失败！");
				}
			},"json");
			
	}
	

</script>
</head>
<body>
<div class="easyui-window" title="干扰告警参数配置" data-options="modal:false,closable:false,minimizable:false,maximizable:false,collapsible:false" style="width:500px;height:400px;padding:10px;">
	<form id="fm" action="" method="post">
		<table cellpadding="6px" url="" fit="true" >
			<tr align="center">
				<th colspan="3" style="padding-bottom: 10px"><big>干扰告警参数配置</big></th>
			</tr>
			<tr> 
			    <td style="text-align:center;width: 100px"">告警级别</td>
			    <td style="text-align:center;width: 200px">有无频谱干扰</td>
			    <td style="text-align:center;width: 150px">RxQual范围</td>
			<tr>
				<td style="text-align:center;width: 100px">1</td>
				<td style="text-align:center;width: 200px">
				    <input class="easyui-combobox" id="haveFSinf1" 
					    data-options="valueField:'lable',textField:'value',
					    data:[{
					                lable:'1',
					                value:'是'
					            },
					            {
					                lable:'0',
					                value:'否'
					            }]" value="1" style="text-align:center;width: 50px" editable="false"/>
			    </td>
				<td style="text-align:center;width: 150px">
				   <input class="easyui-combobox" id="left1" name="left1" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>&nbsp;&nbsp;—&nbsp;&nbsp;
				   <input class="easyui-combobox" id="right1" name="right1" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>
				</td>
			</tr>
			<tr>
				<td style="text-align:center;width: 100px">2</td>
				<td style="text-align:center;width: 200px">
				 <input class="easyui-combobox" id="haveFSinf2" 
					    data-options="valueField:'lable',textField:'value',
					    data:[{
					                lable:'1',
					                value:'是'
					            },
					            {
					                lable:'0',
					                value:'否'
					            }]" value="1" style="text-align:center;width: 50px" editable="false"/>
			    </td>

				<td style="text-align:center;width: 150px">
				   <input class="easyui-combobox" id="left2" name="left2" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>&nbsp;&nbsp;—&nbsp;&nbsp;
				   <input class="easyui-combobox" id="right2" name="right2" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>
				</td>
			</tr>
			<tr>
				<td style="text-align:center;width: 100px">3</td>
				<td style="text-align:center;width: 200px">
                     <input class="easyui-combobox" id="haveFSinf3" 
					    data-options="valueField:'lable',textField:'value',
					    data:[{
					                lable:'1',
					                value:'是'
					            },
					            {
					                lable:'2',
					                value:'0'
					            }]" value="1" style="text-align:center;width: 50px" editable="false"/>
			    </td>
			    <td style="text-align:center;width: 150px">
				   <input class="easyui-combobox" id="left3" name="left3" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>&nbsp;&nbsp;—&nbsp;&nbsp;
				   <input class="easyui-combobox" id="right3" name="right3" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>
				</td>
			</tr>
			<tr>
				<td style="text-align:center;width: 100px">4</td>
				<td style="text-align:center;width: 200px">
				    <input class="easyui-combobox" id="haveFSinf4" 
					    data-options="valueField:'lable',textField:'value',
					    data:[{
					                lable:'1',
					                value:'是'
					            },
					            {
					                lable:'0',
					                value:'否'
					            }]" value="1" style="text-align:center;width: 50px" editable="false"/>
			    </td>
			    <td style="text-align:center;width: 150px">
				   <input class="easyui-combobox" id="left4" name="left4" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>&nbsp;&nbsp;—&nbsp;&nbsp;
				   <input class="easyui-combobox" id="right4" name="right4" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>
				</td>
			</tr>
			<tr>
				<td style="text-align:center;width: 100px">5</td>
                 <td style="text-align:center;width: 200px">
				    <input class="easyui-combobox" id="haveFSinf5" 
					    data-options="valueField:'lable',textField:'value',
					    data:[{
					                lable:'1',
					                value:'是'
					            },
					            {
					                lable:'0',
					                value:'否'
					            }]" value="1" style="text-align:center;width: 50px" editable="false"/>
			    </td>
			    <td style="text-align:center;width: 150px">
				  <input class="easyui-combobox" id="left5" name="left5" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>&nbsp;&nbsp;—&nbsp;&nbsp;
				   <input class="easyui-combobox" id="right5" name="right5" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/alarmvalue.do'" value="-1" style="text-align:center;width: 50px" editable="false"/>
				</td>
			</tr>
			<tr>
				<td colspan="3"></td>
			</tr>
			<c:if test="${currentMemberShip.group.name=='管理员' }">
			<tr>
			    <td>
			    
			    </td>
			    
				<td style="text-align:center;width: 200px">	
					<a href="javascript:submitData()" class="easyui-linkbutton" >应用</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="javascript:refresh()" class="easyui-linkbutton" >刷新</a>
				</td>
			</tr>
			</c:if>
		</table>
	</form>
</div>
</body>
</html>